import {useLocation, useNavigate, useParams, useSearchParams} from "react-router-dom"

function withRouter(WrapperComponent) {
    return function (props) {
        // 1.导航
        const navigate = useNavigate()
        // 2.动态路由的参数 detail/:id
        const params = useParams();
        // 3.查询参数 /user?name=wsb&age=18
        const location = useLocation();
        console.log("location",location)
        // 4.查询参数 /user?name=wsb&age=18
        const [searchParams] = useSearchParams();
        console.log("searchParams",searchParams)

        const query = Object.fromEntries(searchParams);
        const router = {navigate, params, location, query}

        return <WrapperComponent {...props} router={router}/>
    }
}

export default withRouter